#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
#include <strstream.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <errno.h>

#include <string>
#include <iostream>

#define SHMSZ     27


#define SERVER_PORT 5406

#include "Socks4Util.h"
#include "NetCDR.h"

int main(int argc, char** argv)
{
	int Socket;
	Socket = socket(AF_INET,   SOCK_STREAM,   0); 


	struct sockaddr_in lDestAddr;
	lDestAddr.sin_family = AF_INET;
	lDestAddr.sin_port = htons(SERVER_PORT);
	lDestAddr.sin_addr.s_addr = inet_addr( "10.8.32.172"); 


	for(int i = 0; i < 100; i++)
	{
		int Socket;
		Socket = socket(AF_INET,   SOCK_STREAM,   0);

		int   rtnvl_connect = connect(Socket, (struct sockaddr *)&lDestAddr, sizeof(struct sockaddr));
		if(rtnvl_connect < 0)
		{
			std::cout << "error" << strerror(errno) << std::endl;
			return -1;
		}
		std::cout << "connect: " << i << std::endl;
		char szSend[256];
		memset(szSend, 0, sizeof(szSend));



		U8 _version = 4;
		U8 _cmd = 2;
		U16 _port = 22;
		// mildev13
		U32 _ip = inet_addr("10.8.32.115");
		const char* _uid = "scorpio";
		Socks4Util::ConSocks4Cmd(szSend, _version, _cmd, _port, _ip, _uid);

		write(Socket, szSend, 256);
		close(Socket);
	}
	return 0;
}
